import { getRequest, postRequest, putRequest, postBodyRequest, getNoAuthRequest, postNoAuthRequest, postFileRequest } from '@/libs/axios';

export const getAgreementOne = (params) => {
    return getRequest('/agreement/getOne', params)
}
export const getAgreementList = (params) => {
    return getRequest('/agreement/getByPage', params)
}
export const getAgreementCount = (params) => {
    return getRequest('/agreement/count', params)
}
export const addAgreement = (params) => {
    console.log('params参数打印', params)
    return postBodyRequest('/agreement/insert', params)
}
export const editAgreement = (params) => {
    return postRequest('/agreement/update', params)
}
export const addOrEditAgreement = (params) => {
    return postRequest('/agreement/insertOrUpdate', params)
}
export const deleteAgreement = (params) => {
    return postRequest('/agreement/delByIds', params)
}
export const auditAgreement = (params) => {
    return postRequest('/agreement/audit', params)
}
export const notAuditAgreement = (params) => {
    return postRequest('/agreement/notAudit', params)
}
export const signAgreement = (params) => {
    return postRequest('/agreement/sign', params)
}
export const fetchTemplate = () => {
    return getRequest('/template/displayTemplate')
}
export const fetchTemplateData = (tableName, agreementId) => {
    return postRequest(`/template/getTemplateDataByAgreemetnId?tableName=${tableName}&agreementId=${agreementId}`, tableName, agreementId)
}
export const exportWordFile = (data) => {
    return postFileRequest(`/word/export`, data).then(res => {
        const blob = new Blob([res], {
            type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
        });
        const link = document.createElement('a');
        link.href = URL.createObjectURL(blob);
        link.download = `${data.title}.doc`;
        link.click();
        URL.revokeObjectURL(link.href);
    });
};

